import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/IndexView.vue'

// 采用的history写法，如果没有后端在服务器端配合，请使用hash路由，即createWebHashHistory

/**
 * @meta 元信息字段定义
 * title 提供给标题使用
 * topNavMode 区分当前页面顶部导航 默认为全局导航，none为取消全局顶部导航, mainPage不展示左侧返回按钮
 */
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home',
      component: Index,
      meta: { title: '首页' },
      children: [
        {
          path: '/home',
          component: () => import('../views/homeRouterPage/Home.vue'),
          name: 'Index',
          meta: { title: '首页', topNavMode: 'none' }
        },
        {
          path: '/cart',
          component: () => import('../views/homeRouterPage/Cart.vue'),
          name: 'cart',
          meta: { title: '购物车', topNavMode: 'mainPage' }
        },
        {
          path: '/user',
          component: () => import('../views/homeRouterPage/User.vue'),
          name: 'user',
          meta: { title: '个人中心', topNavMode: 'none' },
        },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/index.vue'),
      meta: { title: '登录' }
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/register/index.vue'),
      meta: { title: '注册' }
    },
    // 商品维度
    {
      path: '/search',
      name: 'search',
      component: () => import('../views/productSearchPage/index.vue'),
      meta: { title: '查找商品', topNavMode: 'none' }
    },
    {
      path: '/product/:id(\\d+)',
      name: 'productDetail',
      component: () => import('../views/product/Detail.vue'),
      meta: { title: '商品详情', topNavMode: 'none' }
    },
    // 用户维度：address user
    {
      path: '/addressList',
      name: 'addressList',
      component: () => import('../views/address/AddressList.vue'),
      meta: { title: '地址列表' }
    },
    {
      path: '/addressEdit',
      name: 'addressEdit',
      component: () => import('../views/address/AddressEdit.vue'),
      meta: { title: '编辑地址' }
    },
    {
      path: '/user/accountSecurity',
      component: () => import('../views/homeRouterPage/userChild/AccountSecurity.vue'),
      name: 'accountSecurity',
      meta: { title: '账户安全' },
    },
    {
      path: '/user/info',
      component: () => import('../views/homeRouterPage/userChild/Info.vue'),
      name: 'userInfo',
      meta: { title: '用户信息' },
    },
    // 订单纬度
    {
      path: '/order/preSubmit',
      name: 'preSubmitOrder',
      component: () => import('../views/order/PreSubmit.vue'),
      meta: { title: '提交订单' }
    },
    {
      path: '/order/list',
      name: 'orderList',
      component: () => import('../views/order/List.vue'),
      meta: { title: '订单列表', topNavMode: 'none' }
    },
    {
      path: '/order/dealList',
      name: 'orderDealList',
      component: () => import('../views/order/DealList.vue'),
      meta: { title: '退款/售后' }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    }
  ]
})

export default router
